package com.wyy.controller;

import com.wyy.beans.Resource;
import com.wyy.common.Result;
import com.wyy.service.ResourceService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @PostMapping("/resource")
    @RequiresRoles("admin")
    public Result<Resource> addResource(@RequestBody Resource resource){
        return resourceService.addResource(resource);
    }

    @PutMapping("/resource")
    @RequiresRoles("admin")
    public Result<Resource> updateResource(@RequestBody Resource resource){
        return resourceService.updateResource(resource);
    }

    @DeleteMapping("/resource/{id}")
    @RequiresRoles("admin")
    public Result<Resource> deleteResourceById(@PathVariable long id){
        return resourceService.deleteResourceById(id);
    }

    @GetMapping("/resource/{id}")
    public Resource getResourceById(@PathVariable long id){
        return resourceService.getResourceById(id);
    }

}
